package com.lc.user.express.ordering;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.adapter.FurnitureAdapter;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.httpserver.GetHome;
import com.lc.user.express.model.FurnitureModel;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2016/3/1. 家居
 */
public class FurnitureActivity extends BaseSecondActivity {
    private ListView lv;
    private FurnitureAdapter furnitureAdapter;
    private List<FurnitureModel> list = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_furniture);
        setTitle("家居");
        lv = (ListView)findViewById(R.id.lv);
        lv.setDividerHeight(AppContext.ScaleScreenHelper.getWidthHeight(10));
        furnitureAdapter = new FurnitureAdapter(cnt,list,1);
        lv.setAdapter(furnitureAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putString("id",list.get(position).getId());
                bundle.putString("name",list.get(position).getName());
                show(FurnitureChildActivity.class, bundle);
            }
        });
        getData();
    }
    private void getData(){
        new GetHome("",new AsyCallBack<GetHome.Info>() {
            @Override
            public void onSuccess(String toast, int type, GetHome.Info info) throws Exception {
                list.addAll(info.dataList);
                furnitureAdapter.updateListView(list);
            }
        }).execute(cnt);
    }
}
